import com.sun.net.httpserver.HttpServer;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

// 映射URL地址为 /login
@WebServlet("/login")
public class Login extends HttpServlet {
   @Override
    protected void doget(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
        req.getRequestDispatcher("/login.jsp").forward(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/login.jsp").forward(req, resp);


        // 获取用户名和密码
        String username_login = req.getParameter("username");
        String password_login = req.getParameter("password");
        if ("root".equals(username) && "123123".equals(password)) ;
        {
            resp.sendRedirect(req.getContextPath() + "/stu");
        }else{
            req.setAttribute("msg", "用户名或密码错误");
            req.getRequestDispatcher("login.jsp").forward(req, resp);
        }
    }





